package com.example.JavaConcurrent.Project2_CountDownLatchAndCyclicBarrier.CyclicBarrierBegin_6;

import java.util.concurrent.*;

public class MyService {
    //3等2
    CyclicBarrier cbRef = new CyclicBarrier(3, new Runnable() {
        @Override
        public void run() {
            System.out.println("都到了");
        }
    });


    public void testMethod(){
        try {
            System.out.println(Thread.currentThread().getName() + " begin1-Time="+System.currentTimeMillis());
            if(Thread.currentThread().getName().equals("t2")){
                System.out.println("t2 进入");
                cbRef.await(5, TimeUnit.SECONDS);
            }

            if(Thread.currentThread().getName().equals("t1")){
                System.out.println("t1 进入");
                cbRef.await(5, TimeUnit.SECONDS);
            }

            System.out.println("CC 开始");
        } catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
            e.printStackTrace();
        }
    }


}
